package com.liujit.upms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.liujit.upms.domain.model.SysMenu;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description 系统菜单Mapper
 * @Author liujun
 * @Date 2021-07-02 14:59:44
 */
@Mapper
public interface SysMenuMapper extends BaseMapper<SysMenu> {

    /**
     * 根据用户id， 查询菜单列表
     *
     * @param userId 用户id
     * @return 菜单列表
     * @author: liujun
     * @date: 2021/7/4 10:01 上午
     */
    @Select("select sm.* from"
            + " (select distinct srm.menu_id from sys_user_role sur inner join sys_role_menu srm on srm.role_id = sur.role_id where sur.user_id = #{userId}) t"
            + " inner join sys_menu sm on sm.id = t.menu_id and sm.enabled = 1 order by sm.seq")
    List<SysMenu> selByUserId(Long userId);
}